package com.unc.allergyex.objects.db;
import java.util.ArrayList;

import com.google.gson.Gson;
import com.unc.allergyex.helpers.ObjManager;

/**
 * This class represents the Restaurant/Menu database
 * object.  This object should be created from 
 * the JSON restaurant/menu result string.
 * @author Phillip and Ryan
 */
public class Restaurant {
	private String name;
	private String id;
	private String[] categoryIds;
	private String locationJSON;
	private RestaurantLocation[] locations;
	
	public Restaurant(String locationJSON, String name, String id, String[] categoryIds){
		this.name = name;
		this.id = id;
		this.categoryIds = categoryIds;
		this.locationJSON = locationJSON;
	}
	
	public String getName(){
		return name;
	}
	
	public String getId(){
		return id;
	}
	
	public ArrayList<Category> getCategories(){
		return ObjManager.getCategoryList(categoryIds);
	}
	
	public boolean isChain(){
		RestaurantLocation[] locations = getLocations();
		if (locations.length == 1){
			return false;
		}
		return true;
	}
	
	public RestaurantLocation[] getLocations(){
		if (this.locations == null){
			Gson gson = new Gson();
			RestaurantLocation[] locations = gson.fromJson(locationJSON, RestaurantLocation[].class);
			this.locations = locations;
			return locations;
		}
		else {
			return this.locations;
		}
	}
}
